package com.yx.myinterest;

import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

import com.yx.myinterest.log.LogUtil;

public class MainActivity extends AppCompatActivity {

    private ActivityResultLauncher<Intent> intentActivityResultLauncher;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FileUtils.mContext = this;
        LogUtil.ON_OFF = true;
        setContentView(R.layout.activity_main);
        TextView textView = findViewById(R.id.item_public_video_zan);
        LikeView likeView = findViewById(R.id.item_public_video_love);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                likeView.startDiverges();
            }
        });
        textView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                // 从地下往上弹的Dialog选择框
                new DialogContentOperation(MainActivity.this)
                        .showDialog("是否感兴趣", "msgId");
                return false;
            }
        });


        // 安卓11获得完全存储权限
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
            intent.setData(Uri.parse("package:" + getPackageName()));
            // startActivityForResult(intent, 10001);
            // java写法
            intentActivityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
                @Override
                public void onActivityResult(ActivityResult result) { // B页面setResult()方法传递数据，这部分和以前一样
                    Intent data = result.getData();
                    int resultCode = result.getResultCode();
                }
            });
            if (FileUtils.judgeExternalStorage()) {
                LogUtil.iYx("有所有权限");
            } else {
                LogUtil.iYx("没有所有权限");
                // 打开完全外部存储访问权限申请页面
                intentActivityResultLauncher.launch(intent);
            }
        }

    }


}